#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/types.h>

int main()
{

int pipefd[2];

int pipe_t = pipe(pipefd);
	
if(pipe_t !=0 )
{

perror("create pipe fail!");

}
else
{

pid_t pid = fork();

if(pid < 0)
perror("create task fail");

int num = 0;

while(1){

if(pid > 0)
{

char content[128];

close(pipefd[0]);

sprintf(content,"this is pipe stream ---> %d\n",num);

num++;

write(pipefd[1], content, strlen(content));	

//int status;

//wait(&status);
}

if(pid == 0)
{

sleep(2);

close(pipefd[1]);

char buff[128];

read(pipefd[0], (void *)buff, sizeof(buff)/sizeof(*buff));

puts(buff);

}

}
}


return 0;
}


